<style type="text/css">
    .sDiv {
        float: right;
        position: relative;
        overflow: hidden;
    }
    .sDiv2 {
        margin-right: 10px;
        font-size: 0;
        display: inline-block;
        vertical-align: middle;
        border: solid 1px #D7D7D7;
        border-radius: 5px;
    }
    .sDiv2 .qsbox {
        background-color: #FFF;
        font-size: 12px;
        line-height: 24px;
        width: 140px;
        height: 24px;
        padding: 1px 5px;
        border: none;
        /*font-size: 12px;*/
        vertical-align: top;
        letter-spacing: normal;
        display: inline-block;
        border-radius: 0;
    }
    .sDiv2 .abtn {
        border: none;
        border-radius: 0;
        font-size: 12px;
        vertical-align: top;
        letter-spacing: normal;
        display: inline-block;
    }
    .sDiv2 .abtn {
        height: 26px;
        line-height:26px;
        cursor: pointer;
        border-left: solid 1px #D7D7D7;
    }
</style>
<include file="common:__head__"/>
<div class="permissions-tabs">
    <a class="role tabs-bg" href="{:U('report/agent_ranking')}">代理统计</a>
</div>
<div class="permissions-content">
    <div class="permissions-le">
        <div class="add-msg">
            <div class="add-form">
                <div class="sDiv">
                    <div class="sDiv2" style="margin-right: 10px;">
                        <input type="text" size="30" name="start_time" id="start_time" value="{$start_time}" placeholder="起始时间"
                               class="qsbox">
                        <input type="button" class="abtn" style="padding-left: 2px;width:75px" value="起始时间">
                    </div>
                    <div class="sDiv2" style="margin-right: 10px;">
                        <input type="text" size="30" name="end_time" id="end_time" value="{$end_time}" placeholder="截止时间"
                               class="qsbox">
                        <input type="button" class="abtn" style="padding-left: 2px;width:75px" value="截止时间">
                    </div>
                <input type="hidden" id="orderby1" value="id"/>
                <input type="hidden" id="orderby2" value="DESC"/>
                <a class="btn btn-blue" style="height:30px;line-height:30px;" onclick="ajax_get();">搜索</a>
                </div>
            </div>
        </div>
        <div class="permissions-table">
            <table border="0" width="100%" class="keep_on">
                <thead>
                <tr>
                    <td width="15%">代理排行</td>
                    <td width="40%">代理名称</td>
                    <td onclick="orderby('sumnum DESC')"><a style="color: deepskyblue;cursor: pointer">订单数量</a></td>
                    <td onclick="orderby('sumprice DESC')"><a style="color: deepskyblue;cursor: pointer">代理订单销售额</a></td>
                </tr>
                </thead>
                <tbody class="ready">
                <foreach name="res" item="vo" key="k" >
                    <tr>
                        <td>{$k+1}</td>
                        <td>{$vo.agent_name}</td>
                        <td>{$vo.sumnum}</td>
                        <td>{$vo.sumprice}</td>
                    </tr>
                </foreach>
                </tbody>
            </table>
        </div>
    </div>
    <div class="permissions-ri">
        <a href="" class="permissions-help">帮助和服务</a>
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/plugins/layer/laydate/laydate.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function () {
            $(this).toggleClass('trSelected');
        });
    });

    function ajax_get(){
        var start_time = $('#start_time').val();
        var end_time = $('#end_time').val();

        if(!start_time || !end_time){
            layer.msg("时间不能为空");return false;
        }

        var start_timestamp = Date.parse(new Date(start_time));
        start_timestamp = start_timestamp / 1000;

        var end_timestamp = Date.parse(new Date(end_time));
        end_timestamp = end_timestamp/1000;

        if(start_timestamp > end_timestamp){
            layer.msg("开始时间必须大于结束时间");return false;
        }
        $.ajax({
            url:"{:U('Report/agent_ranking')}",
            type:"post",
            data:{
                start_time : start_time,
                end_time : end_time
            },
            success:function (msg) {
                layer.msg("加载中",{time:1000});
                setTimeout(function() {
                    $(".ready").remove();
                    $(".keep_on").append(msg);
                }, 1000);
            }
        })
    }

    function orderby(data) {
        $.ajax({
            url:"{:U('Report/agent_ranking')}",
            type:"post",
            data:{
                orderby : data
            },
            success:function (msg) {
                layer.msg("加载中",{time:700});
                setTimeout(function() {
                    $(".ready").remove();
                    $(".keep_on").append(msg);
                }, 700);
            }
        })
    }

    $(function() {
        //日历插件
        $('#start_time').layDate();
        $('#end_time').layDate();
    });

</script>
<include file="common:__foot__"/>